/**
 *
 */
package com.wedroid.r2d2.message;

import org.apache.commons.lang3.StringEscapeUtils;

import com.wedroid.entity.message.AppMessageType;
import com.wedroid.r2d2.utils.XmlStringUtils;

/**
 * @author lute
 *
 */
public class ShareInfo {

    private String title;

    private String description;

    private String url;

    private String lowUrl;

    private String dataUrl;

    private String lowDataUrl;

    private String thumbUrl;

    private String appName;

    private AppMessageType appMessageType;

    /**
     *
     */
    public ShareInfo() {

    }

    /**
     * @param rawMessage
     * @param shareContent
     */
    public ShareInfo(RawMessage rawMessage, String shareContent) {
        this.title = rawMessage.getFileName();
        this.description = XmlStringUtils.findElement("des", shareContent);
        this.url = StringEscapeUtils.unescapeHtml4(rawMessage.getUrl());
        this.lowUrl = StringEscapeUtils.unescapeHtml4(XmlStringUtils.findElement("lowurl", shareContent));
        this.dataUrl = StringEscapeUtils.unescapeHtml4(XmlStringUtils.findElement("dataurl", shareContent));
        this.lowDataUrl = StringEscapeUtils.unescapeHtml4(XmlStringUtils.findElement("lowdataurl", shareContent));
        this.appName = XmlStringUtils.findElement("appname", shareContent);
        this.appMessageType = AppMessageType.codeOf(rawMessage.getAppMsgType());
    }

    /**
     * Set thumb URL
     *
     * @param thumbUrl
     * @return
     */
    public ShareInfo thumb(String thumbUrl) {
        this.thumbUrl = thumbUrl;
        return this;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("App Message [").append(appMessageType.name()).append("] from ")
            .append(appName).append(": ")
            .append(title).append(" (").append(url).append(")");
        return stringBuilder.toString();
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @return the lowUrl
     */
    public String getLowUrl() {
        return lowUrl;
    }

    /**
     * @return the dataUrl
     */
    public String getDataUrl() {
        return dataUrl;
    }

    /**
     * @return the lowDataUrl
     */
    public String getLowDataUrl() {
        return lowDataUrl;
    }

    /**
     * @return the thumbUrl
     */
    public String getThumbUrl() {
        return thumbUrl;
    }

    /**
     * @return the appName
     */
    public String getAppName() {
        return appName;
    }

    /**
     * @return the appMessageType
     */
    public AppMessageType getAppMessageType() {
        return appMessageType;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @param lowUrl the lowUrl to set
     */
    public void setLowUrl(String lowUrl) {
        this.lowUrl = lowUrl;
    }

    /**
     * @param dataUrl the dataUrl to set
     */
    public void setDataUrl(String dataUrl) {
        this.dataUrl = dataUrl;
    }

    /**
     * @param lowDataUrl the lowDataUrl to set
     */
    public void setLowDataUrl(String lowDataUrl) {
        this.lowDataUrl = lowDataUrl;
    }

    /**
     * @param thumbUrl the thumbUrl to set
     */
    public void setThumbUrl(String thumbUrl) {
        this.thumbUrl = thumbUrl;
    }

    /**
     * @param appName the appName to set
     */
    public void setAppName(String appName) {
        this.appName = appName;
    }

    /**
     * @param appMessageType the appMessageType to set
     */
    public void setAppMessageType(AppMessageType appMessageType) {
        this.appMessageType = appMessageType;
    }

}
